package pro.cherish.knowledgeumldesignpattern.designPattern.com.cherish.itrator;

import java.util.HashSet;
import java.util.Iterator;

//迭代器模式经常用像jdk内置的迭代器如list/set这些实现connector ->iterator
public class client {
    public static void main(String [] args){
        ConcreteMyAggregate concreteMyAggregate = new ConcreteMyAggregate();
        concreteMyAggregate.addObject("aa");
        concreteMyAggregate.addObject("bb");
        concreteMyAggregate.addObject("cc");
        concreteMyAggregate.addObject("dd");
        MyIterator iterator = concreteMyAggregate.createIterator();
        while (iterator.hashNext()){
//            这里的迭代遍历时获取当期和游标下移分开，而jdk中的迭代是next包括获取和下移动
            Object currentObj = iterator.getCurrentObj();
            System.out.println(currentObj);
            iterator.next();
        }
        HashSet<Object> objects = new HashSet<>();
        Iterator<Object> iterator1 = objects.iterator();
    }
}
